package com.dyh.quickdemozwei;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Setter@Getter
public class WrTest2 {

    volatile boolean stop=false;
    volatile Map<String,String> sm = new HashMap<>();


    private Runnable r = ()->{
        for (;;){
            //1
//            System.out.println(stop);

            //2
//            log.info("stop={}",stop);

            //3
//            try {
//                Thread.sleep(100);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            if (stop){
//                log.info("catch stop={}",stop);
//                break;
//            }

            if ("xx".equals(sm.get("k"))){
                log.info("catch ");

                break;
            }


        }
        log.info("end");
    };





    public static void main(String[] args) throws InterruptedException {
        WrTest2 wrTest2 = new WrTest2();
        Thread t1 = new Thread(wrTest2.r);
        log.info("start");
        t1.start();

        Thread.sleep(1000);
//        wrTest2.stop = true;
        Map<String,String> nm = new HashMap<>();
        nm.put("k","xx");

        wrTest2.sm = nm;
//        wrTest2.sm.put("k","xx");
        t1.join();

    }
}
